<!DOCTYPE html>
<html>
<head>
    <title>Deferred</title>
    <meta charset="utf-8"/>
    <script src="../../../js/jquery-1.10.1.min.js"></script>
    <script>

        // Existing object
        var obj = {
                    hello: function( name ) {
                        alert( "Hello " + name );
                    }
                },
        // Create a Deferred
        defer = $.Deferred();

        // Set object as a promise
        defer.promise( obj );

        // Use the object as a Promise
        obj.done(function( name ) {
            obj.hello( name ); // Will alert "Hello John"
        }).hello( "Karl" ); // Will alert "Hello Karl"

        // Resolve the deferred
        defer.resolve( "John" );

    </script>
</head>
<body>
    <p>Deferred--Deferred</p>
</body>
</html>